// createUserList 该函数执行时回返回一个数组，数组包含两个用户信息
function createUserList() {
    return [
        {
            adminName: 'fengfeng',
            adminPassword: '111111',
            token: 'My Token',
        }
    ]
}

const getPageInfo = (url,name)=>{
    let pageInfo = url.split('?')
    let pageArr = pageInfo[1].split('&')
    for (const item of pageArr) {
        let page = item.split('=')
        if(page.indexOf(name)!=-1){
            console.log(Number(page[1]))
            return Number(page[1])
        }
    } 
}


export default [
    {
        url: '/login',
        method: 'post',
        response: ({ body }) => {
            //获取请求体携带的用户密码
            const { adminName, adminPassword } = body;
            const checkUser = createUserList().find(el => el.adminName == adminName && el.adminPassword == adminPassword)
            //如果没有用户返回失败的信息
            if (!checkUser) {
                return { code: 400, data: { messages: '账号或密码错误' } }
            }
            //存在该用户者返回成功信息
            const { token } = checkUser
            return { code: 200, data: { token } }

        }
    },
    {
        url: '/bytoken',
        method: 'get',
        response: (request) => {
            //获取请求头
            const token = request.headers.Authorization;
            //调用createUserList 函数，检查用户的存在
            const checkUser = createUserList().find(item => item.token)
            if (!checkUser) {
                return { code: 400, messages: '获取失败' }
            }
            return {
                code: 200, messages: '获取教师信息', data: { checkUser }
            }
        }
    },
   
]